using UnityEngine;
using System.Collections;
using System;

public class NewBehaviourScript : MonoBehaviour 
{
    private string url = "https://graph.facebook.com/me/photos", 
        response = "", error = "";
    void OnGUI()
    {
        GUILayout.Label("URL:");
        url = GUILayout.TextField(url);
        if (GUILayout.Button("Test"))
        {
            response = error = "";
            SendTextRequest(url, delegate(string re)
            {
                response = re;
            });
        }
        GUILayout.Label("Response:");
        GUILayout.TextField(response);
        GUILayout.Label("Error:");
        GUILayout.TextField(error);
    }
	public void SendTextRequest(string url, Action<string> callBack)
    {
		StartCoroutine(sendRequest(url, callBack));
    }
    private IEnumerator sendRequest(string url, Action<string> callBack)
    {
        WWW request = new WWW(url);
        while (!request.isDone)
        {
            yield return new WaitForSeconds(.3f);
        }
        print(request.text);
        error = request.error;
        if (callBack != null)
        {
            callBack(request.text);
        }
        request.Dispose();
    }
}
